<template>
  <div>
    <!--头部-->
    <header class="publicHeader">
      <h1>超市订单管理系统</h1>
      <div class="publicHeaderR">
        <p><span>下午好！</span><span style="color: #fff21b"> 系统管理员</span> , 欢迎你！</p>
        <a href="jsp/logout.do">退出</a>
      </div>
    </header>
    <!--时间-->
    <section class="publicTime">
      <span id="time">2015年1月1日 11:11  星期一</span>
      <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
    </section>
    <!--主体内容-->
    <section class="publicMian ">
      <div class="left">
        <h2 class="leftH2"><span class="span1"></span>功能列表 <span></span></h2>
        <nav>
          <ul class="list">
            <li><a href="jsp/bill.do?method=query">订单管理</a></li>
            <li><a href="#/providerManager">供应商管理</a></li>
            <li><a href="jsp/user.do?method=query">用户管理</a></li>
            <li><a href="jsp/pwdmodify.jsp">密码修改</a></li>
            <li><a href="jsp/logout.do">退出系统</a></li>
          </ul>
        </nav>
      </div>
      <input type="hidden" id="path" name="path" value="/SMBMS"/>
      <input type="hidden" id="referer" name="referer" value="http://localhost:8080jsp/provider.do?method=query"/>

      <div class="right">
        <div class="location">
          <strong>你现在所在的位置是:</strong>
          <span>供应商管理页面 >> 供应商修改页</span>
        </div>
        <div class="providerAdd">
          <!--div的class 为error是验证错误，ok是验证成功-->
          <div class="">
            <label for="proCode">供应商编码：</label>
            <input type="text" name="proCode" id="proCode" v-model="provider.proCode" readonly="readonly">
          </div>
          <div>
            <label for="proName">供应商名称：</label>
            <input type="text" name="proName" id="proName" v-model="provider.proName">
            <font color="red"></font>
          </div>

          <div>
            <label for="proContact">联系人：</label>
            <input type="text" name="proContact" id="proContact" v-model="provider.proContact">
            <font color="red"></font>
          </div>

          <div>
            <label for="proPhone">联系电话：</label>
            <input type="text" name="proPhone" id="proPhone" v-model="provider.proPhone">
            <font color="red"></font>
          </div>

          <div>
            <label for="proAddress">联系地址：</label>
            <input type="text" name="proAddress" id="proAddress" v-model="provider.proAddress">
          </div>

          <div>
            <label for="proFax">传真：</label>
            <input type="text" name="proFax" id="proFax" v-model="provider.proFax">
          </div>

          <div>
            <label for="proDesc">描述：</label>
            <input type="text" name="proDesc" id="proDesc" v-model="provider.proDesc">
          </div>
          <div class="providerAddBtn">
            <input type="button" name="save" id="save" value="保存" @click="updateProvider">&nbsp;&nbsp;
            <input type="button" id="back" name="back" value="返回" @click="backToProvider">
          </div>
        </div>
      </div>
    </section>


    <footer class="footer">
      版权归关老师
    </footer>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "ProviderUpdate",
  data() {
    return {
      provider: {
        id: 0,
        proCode: '',
        proName: '',
        proPhone: '',
        proAddress: '',
        proFax: '',
        proContact: '',
        proDesc: ''
      }
    }
  },
  created() {
    this.provider.id = this.$route.query.id
    this.loadProviderById()
  },
  methods: {
    loadProviderById() {
      console.log(this.provider.id)
      console.log(this.provider)
      let _this = this
      axios.get('/api/smbms-provider/provider/id/' + this.provider.id)
          .then((respoinse) => {
            _this.provider = respoinse.data.data
          })
    },
    updateProvider() {
      let _this = this
      let data = new URLSearchParams()
      data.append('proCode', this.provider.proCode)
      data.append('proName', this.provider.proName)
      data.append('proPhone', this.provider.proPhone)
      data.append('proFax', this.provider.proFax)
      data.append('proAddress', this.provider.proAddress)
      data.append('proContact', this.provider.proContact)
      data.append('proDesc', this.provider.proDesc)
      data.append("id", this.provider.id)
      data.append('page', 1)
      axios({
        url: '/api/smbms-provider/provider',
        method: 'put',
        data: data
      }).then((response) => {
        if (response.data.success) {
          _this.$router.push('providerManager')
        }
      })
    }
  }
}
</script>

<style lang="css">
/*引入外部css文件*/
@import url('../assets/css/style.css');
@import url('../assets/css/public.css');
</style>